<?php

/*

Club forums (club_forums.php)

*/

$page_title = "Club Forums";
$rank_check = 1;
include "header.inc.php";
$clubrank_check = 1;
$page_heading = "Forums (<a href=$base_url/club_forums.php?game=$game&clubid=$clubid&act=post_message><font color=\"$topAndBottomText\">Post new message</font></a>)";
include "club.inc.php";

echo $openHTML;
echo $startClub;

function post_form($subject = "",$thread = "")
{
	include "globals.inc.php";
	return "<p>Subject:<br><input type=text maxlength=48 size=32 name=subject value=\"$subject\"><br>Message:<br><textarea name=message rows=8 cols=32></textarea><br><input type=submit name=submit value=Post></p>";
}

if (!$act)
{
	$act = "list_topics";
}

if ($act == "list_topics")
{
ECHO <<<FORUM

<CENTER><FONT COLOR="$topAndBottomText"><B><a href=club_forums.php?game=$game&clubid=$clubid class=forum>Club Forums</a><br><a href=$base_url/club_forums.php?game=$game&clubid=$clubid&act=post_message>Post new message!</a></B></FONT></CENTER>

<CENTER><BR> <TABLE BGCOLOR="$tableOutline" CELLSPACING=1 CELLPADDING=0 WIDTH=95%>

<tr width=100% bgcolor=$topAndBottomBG><td colspan=3><p><font color=$topAndBottomText>Topics:</font></p></td></tr>

FORUM;

	$query = mysql_query("SELECT id,subject,author,replies,last FROM club_forums2 WHERE club = '$clubid' AND type = '1' AND game = '$game' ORDER BY last LIMIT 100");

	while ($array = mysql_fetch_array($query))
	{
		$author = fetch("SELECT username,display_name FROM members2 WHERE id = '$array[author]' AND game = '$game'");
		$last = date("M j @ H:i:s ",$array[last]);
		$cellcolor = alternate($cellcolor,"$reallyLight","#FFFFFF");
		$get_responder = fetch("SELECT username,display_name FROM members2 WHERE id = '$array[last_post_by]'");

		echo "
		<tr bgcolor=$cellcolor onmouseover=\"this.style.background='$middleBG';\" onmouseout=\"this.style.background='$cellcolor';\" width=100%>
<td><p><a href=$base_url/club_forums.php?game=$game&clubid=$clubid&act=view_topic&topic=$array[id]>$array[subject]</a> $delete<br><font size=-1><i>Posted by <a href=$base_url/user_profile.php?game=$game&user=$author[username]>$author[display_name]</a></i></font></p></td>
<td width=75><center>$array[replies]</center></td>
<td width=125><center><font size=-1>Last post at:<Br>$last</font></center></td>
</tr>";

	}
	print "</table><br>";
}
if ($act == "view_topic")
{
	$message = fetch("SELECT id,author,posted,subject,message FROM club_forums2 WHERE club = '$clubid' AND id = '$topic' AND game = '$game'");

if ($clubrank >= 2)
{
	$deleteLink = " (<a href=club_forum_delete.pro.php?game=$game&clubid=$clubid&type=topic&id=$message[id] onClick=\"if ( !confirm ('Are you sure you want to delete this post?') ) { return false; }\">Delete</a>)";
}

	$author = fetch("SELECT username,display_name FROM members2 WHERE id = '$message[author]' AND game = '$game'");
	$posted = date("H:i:s D M j",$message[posted]);

	print "

	<CENTER><B><a href=club_forums.php?game=$game&clubid=$clubid class=forum>Club Forums</a><BR>$message[subject]</B></CENTER

	<CENTER><table width=95% BGCOLOR=\"$middleBG\" CELLSPACING=1 CELLPADDING=0 width=95%><tr bgcolor=$topAndBottomBG><td colspan=2><p><font color=\"$topAndBottomText\">Posted By: <a href=$base_url/user_profiles.php?game=$game&user=$author[username]>$author[display_name]</a> at $posted $deleteLink</font></td></tr><tr><td BGCOLOR=$maincellColor colspan=2>$message[message]</a></b></i></u></td></tr><tr bgcolor=$topAndBottomBG><td colspan=2><p><font color=$topAndBottomText>Replies:</font></td></tr>";

	$query = mysql_query("SELECT id,author,posted,subject,message FROM club_forums2 WHERE club = '$clubid' AND type = '2' AND thread = '$topic' AND game = '$game' ORDER BY id LIMIT 100");
	while ($array = mysql_fetch_array($query))
	{
		if ($clubrank >= 2)
		{
			$deleteLink = "<br> (<a href=club_forum_delete.pro.php?game=$game&clubid=$clubid&type=reply&topic=$topic&id=$array[id] onClick=\"if ( !confirm ('Are you sure you want to delete this post?') ) { return false; }\">Delete</a>)";
		}
		$bgcolor = alternate($bgcolor,"$maincellColor", "$middleBG");
		$author = fetch("SELECT username,display_name FROM members2 WHERE id = '$array[author]' AND game = '$game'");
		$posted = date("H:i:s D M j",$array[posted]);
		$cellcolor = alternate($cellcolor,"$reallyLight","#FFFFFF");

		echo "<tr bgcolor=$cellcolor width=100%><td width=125 valign=top bgcolor=$cellcolor><p><font size=-1>Reply By:<br><a href=$base_url/user_profiles.php?game=$game&user=$author[username]>$author[display_name]</a><Br>
At: $posted<br>$deleteLink</font></p></td><td valign=top bgcolor=$cellcolor>$array[message]</a></b></i></u></td></tr>";
	}
	echo "</table><form action=$base_url/club_post.pro.php?game=$game&clubid=$clubid method=post><input type=hidden name=thread value=$topic><input type=hidden name=type value=2>";
	echo post_form("Re: $message[subject]",$message[id]);
}
if ($act == "post_message")
{
	print "<form action=$base_url/club_post.pro.php?game=$game&clubid=$clubid method=post><input type=hidden name=thread value=$topic><input type=hidden name=type value=1>";
	echo post_form();
}

echo "</form>";
echo $endClub;
echo $closeHTML;

?>